programs

program
Programs consist of a prolog, followed by one or more functions.  Programs may be terminated by an END PROGRAM statement after the last function, but it is not required.

The following program contains a 2 line prolog and a 3 line function:

DECLARE FUNCTION Hello ()       ' PROLOG - declare program function
'                               ' PROLOG - comment line
FUNCTION Hello ()               ' FUNCTION - begin function definition
  PRINT "Hello World"           ' FUNCTION - function body or contents
END FUNCTION                    ' FUNCTION - end function definition

PROLOG
A prolog consists of the following elements in the listed order:

1.  declarations of all external programs/libraries referenced by the program, if any.
2.  declarations/definitions of all user-defined data-types, if any.
3.  declarations of all functions in the program (at least one).
4.  declarations of special external functions called by program (optional).
5.  declarations of shared & external variables, if any (optional).
6.  declarations/definitions of all shared constants, if any.

The first declared function is the entry function - execution begins here when the program is run.

The functions declared in the prolog immediately follow the prolog.  Only blank lines and comment lines may appear between functions.  Comment lines and blank lines between functions are associated with the function that follows, so function comments must precede the function they describe.

PROLOG elements example
PROGRAM "trouble"             ' name the program or library
VERSION "0.0000"              ' keep version number updated
IMPORT "xst"                  ' make standard library available
IMPORT "mylib"                ' make custom library available
'
EXPORT                        ' begin exporting types, funcs, etc
TYPE HANDLE = XLONG           ' declare user-defined type HANDLE
TYPE LINK                     ' declare user-defined type LINK
  XLONG .backward             ' define component of type LINK
  XLONG .forward              ' define component of type LINK
END TYPE                      ' end declaration of type LINK
'
DECLARE FUNCTION Entry ()     ' declare function in this program
END EXPORT                    ' stop exporting (temporarily)
'
SHARED lastIndex, thisIndex   ' declare shared variables
EXTERNAL flexStatus           ' declare external variable
EXPORT                        ' resume exporting
$$Off = 0                     ' define and export shared constant
$$On = -1                     ' define and export shared constant
END EXPORT                    ' stop exporting (the end)